<?php

class connect_db {
	private $username;
	private $password;
	private $hostname;
	private $dbname;
	private $link;
	private $result;
	private $numerorighe;
	private $app;
	
	function __construct() {
		$this->Set_Username('root');
		$this->Set_Password('root');
		$this->Set_Hostname('localhost');
		$this->dbname = 'universaleshop';
		$this->link = null;
		$this->result = null;
		$this->numerorighe = null;
		$this->app = null;
	}
	
	function connectSQL() {
		$this->link=mysql_connect($this->hostname,$this->username,$this->password) or die ("ATTENZIONE: impossibile connettersi al DB!!! ".mysql_error());
	}

	function Set_Username($user) {
		$this->username=$user;
	}
	
	function Set_Hostname($host) {
		$this->hostname=$host;
	}
	
	function Set_Password($pass) {
		$this->password=$pass;
	}
	
	function Set_DB($nome_db) {
		$this->dbname=$nome_db;
		mysql_select_db($nome_db, $this->link);
		mysql_error();
	}
	/*
	function ConnectSQL_db($dbname) {
		$link=mysql_pconnect($this->hostname, $this->username,$this->password) or die("Errore!!! Non posso connettermi... ".mysql_error());
		$this->Set_DB($dbname);
	}
	*/
	function Exec_Query($query) {
		$this->Set_DB($this->dbname);
		$this->result=mysql_query($query);
		if ($this->result ==false) {
			print "errore esecuzione query: ". mysql_error(). "<br>";
	   		exit();
		}
		return $link;
	}
	
	function ReturnResult($num,$campo) {
		$app=$this->ReturnNum();
		if($app!=0)	{
			$result=mysql_result($this->result,$num,$campo);
			return($result);
		} else {
			return("Vuoto");
		}	
	}
	
	function ReturnNum() {
		$numerorighe=mysql_num_rows($this->result);
		return($numerorighe);
	}
	
	function DisconnectSQL() {
		mysql_close($this->link);
	}

}

?>